<?php
/**
 * Product:     One-Page Checkout Booster
 * Package:     Gold_Gonepage_1.1.1_94708
 * Purchase ID: 9CBm2i1g9YwZZ6QK4IjUneSwxlnJsImwioL1MUWAXd
 * Generated:   2011-07-15 10:07:59
 * File path:   app/code/local/Gold/Gonepage/Helper/Data.php
 * Copyright:   (c) 2011 GOLD, Inc.
 */
class Gold_Gonepage_Helper_Data extends Gold_Gonepage_Helper_Abstract
{
    
    const IS_SHOW_CHECKOUT_OUTSIDE_CART = 0;
    const IS_SHOW_CHECKOUT_IN_CART = 1;
    const IS_SHOW_CART_IN_CHECKOUT = 2;
    const IS_DISABLED = 3;
    
    const DESIGN_DEFAULT = 0;
    const DESIGN_COMPACT = 1;
    
    protected $_checkoutShowMethod = null;
    protected $_designType         = null;
    
    protected $_rule = null; 
    
    protected function _getCheckoutShowMethod()
    {
        if (is_null($this->_checkoutShowMethod))
        {
            $this->_checkoutShowMethod = Mage::getStoreConfig('checkout/gonepage/checkout_show_method');
        }
        return $this->_checkoutShowMethod;
    }
    
    protected function _getDesignType()
    {
        if (is_null($this->_designType))
        {
            $this->_designType = Mage::getStoreConfig('checkout/gonepage/design_type');
        }
        return $this->_designType;
    }
    
    public function isShowCheckoutInCart()
    {         
        return (self::IS_SHOW_CHECKOUT_IN_CART == $this->_getCheckoutShowMethod());   
    }
    
    public function isDisabled()
    {         
        return (self::IS_DISABLED == $this->_getCheckoutShowMethod() || !Mage::getStoreConfigFlag('checkout/options/onepage_checkout_enabled'));   
    }
    
    public function isShowCheckoutOutsideCart()
    {         
        return (self::IS_SHOW_CHECKOUT_OUTSIDE_CART == $this->_getCheckoutShowMethod());   
    }
    
    public function isShowCartInCheckout()
    {         
        return (self::IS_SHOW_CART_IN_CHECKOUT == $this->_getCheckoutShowMethod());   
    }
    
    public function isCompactDesign() 
    {
        return (self::DESIGN_COMPACT == $this->_getDesignType() );
    }
    
    public function isShowProceedToCheckoutButton()
    {
        if ($this->isShowCheckoutInCart())
        {
            return Mage::getStoreConfig('checkout/gonepage/show_proceed_to_checkout_button');       
        }
        return true;    
    }
    
    public function isShowCheckoutTitle()
    {
        return Mage::getStoreConfigFlag('checkout/gonepage/show_title');              
    }
    
    public function getCheckoutTitle()
    {
        return Mage::getStoreConfig('checkout/gonepage/title_text');    
    }
    
    public function getCheckoutUrl()
    {
        if ($this->isShowCheckoutInCart())
        {
            return $this->getCartUrl();
        }
        return 'gonepage/checkout';    
    }     
     
    public function getCartUrl()
    {
        if ($this->isShowCartInCheckout())
        {
            return $this->getCheckoutUrl();
        }
        return 'checkout/cart';    
    }
    
    private function _checkRule()
    {
        if(is_null($this->_rule))
        {
            $this->_rule = true;
            /* */
            $iStoreId = Mage::app()->getStore()->getId();
            $iSiteId  = Mage::app()->getWebsite()->getId();
            $performer = Gold_Goldsys_Abstract_Service::get()->platform()->getModule('Gold_Gonepage')->getLicense()->getPerformer();
            $ruler     = $performer->getRuler();
            if (!($ruler->checkRule('store', $iStoreId, 'store') || $ruler->checkRule('store', $iSiteId, 'website')))
            {
                $this->_rule = false;
            }
            /* */
        }
    
        return $this->_rule;
    }
    
    public function canEditCartItems()
    {
        if (Gold_Goldsys_Abstract_Service::get()->isMagentoVersion('>=1.5'))
        {
            return true;
        }
        return false;    
    }
    
    public function getReviewTotalsColspan()
    {
        if($this->isCompactDesign() && $this->isShowCartInCheckout()) {
            return 2;
        }
        $isDisplayTax = Mage::helper('tax')->displayCartBothPrices() ? 2 : 0;
        $isAllowWishlist = Mage::helper('wishlist')->isAllowInCart() ? 1 : 0;
        $canEditCartItems = $this->canEditCartItems() ? 1 : 0;
        $isShowCheckoutInCart = $this->isShowCartInCheckout() ? 1 : 0;

        return ($this->isShowCartInCheckout() ? 5 : 3) 
            + $isAllowWishlist  * $isShowCheckoutInCart
            + $canEditCartItems * $isShowCheckoutInCart
            + $isDisplayTax; 
    } 
    
    public function getDefaultCountry()
    {
        if (Gold_Goldsys_Abstract_Service::get()->isMagentoVersion('>=1.5'))
        {
            return Mage::helper('core')->getDefaultCountry();   
        }
        else {
            return Mage::getStoreConfig('general/country/default');                                         
        }
    } 
    
    
        
}